import React from 'react';
import { useEffect } from 'react';
import { BrowserRouter as Router, Routes, Route,useLocation } from 'react-router-dom';
import Login from './pages/login';
import Home from "./pages/home"; // 导入Login组件
import Phone1 from "./pages/phone/phone1";
import Phone2 from "./pages/phone/phone2";
import Phone3 from "./pages/phone/phone3";
import Phone4 from "./pages/phone/phone4";
import Phone5 from "./pages/phone/phone5";
import Phone6 from "./pages/phone/phone6";
import Phone7 from "./pages/phone/phone7";
import Phone8 from "./pages/phone/phone8";
import Tablet1 from "./pages/tablet/tablet1";
import Tablet2 from "./pages/tablet/tablet2";
import Tablet3 from "./pages/tablet/tablet3";
import Tablet4 from "./pages/tablet/tablet4";
import Tablet5 from "./pages/tablet/tablet5";
import Tablet6 from "./pages/tablet/tablet6";
import Tablet7 from "./pages/tablet/tablet7";
import Tablet8 from "./pages/tablet/tablet8";
import Computer1 from "./pages/computer/computer1";
import Computer2 from "./pages/computer/computer2";
import Computer3 from "./pages/computer/computer3";
import Computer4 from "./pages/computer/computer4";
import Computer5 from "./pages/computer/computer5";
import Computer6 from "./pages/computer/computer6";
import Computer7 from "./pages/computer/computer7";
import Computer8 from "./pages/computer/computer8";
//保证跳转路由后在页面顶部
function ScrollToTop() {
    const { pathname } = useLocation();

    useEffect(() => {
        window.scrollTo(0, 0);
    }, [pathname]);

    return null;
}

function App() {
    return (
        <Router>
            <ScrollToTop />
            <Routes>
                <Route path="/" element={<Login />} />
                <Route path="/home" element={<Home />} />
                <Route path="/phone1" element={<Phone1 />}></Route>
                <Route path="/phone2" element={<Phone2 />}></Route>
                <Route path="/phone3" element={<Phone3 />}></Route>
                <Route path="/phone4" element={<Phone4 />}></Route>
                <Route path="/phone5" element={<Phone5 />}></Route>
                <Route path="/phone6" element={<Phone6 />}></Route>
                <Route path="/phone7" element={<Phone7 />}></Route>
                <Route path="/phone8" element={<Phone8 />}></Route>
                <Route path="/computer1" element={<Computer1 />}></Route>
                <Route path="/computer2" element={<Computer2 />}></Route>
                <Route path="/computer3" element={<Computer3 />}></Route>
                <Route path="/computer4" element={<Computer4 />}></Route>
                <Route path="/computer5" element={<Computer5 />}></Route>
                <Route path="/computer6" element={<Computer6 />}></Route>
                <Route path="/computer7" element={<Computer7 />}></Route>
                <Route path="/computer8" element={<Computer8 />}></Route>
                <Route path="/tablet1" element={<Tablet1 />}></Route>
                <Route path="/tablet2" element={<Tablet2 />}></Route>
                <Route path="/tablet3" element={<Tablet3 />}></Route>
                <Route path="/tablet4" element={<Tablet4 />}></Route>
                <Route path="/tablet5" element={<Tablet5 />}></Route>
                <Route path="/tablet6" element={<Tablet6 />}></Route>
                <Route path="/tablet7" element={<Tablet7 />}></Route>
                <Route path="/tablet8" element={<Tablet8 />}></Route>
            </Routes>
        </Router>
    );
}

export default App;